<template>
  <!-- 退款管理 -->
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button
          type="primary"
          icon="el-icon-plus"
          @click="add"
          v-auth-button="['add/refund']"
        ></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-input
            v-model="searchValue.contractCode"
            placeholder="合同编码"
            clearable
          ></el-input>
          <el-input
            v-model="searchValue.customerName"
            placeholder="客户名称"
            clearable
          ></el-input>
          <el-select
            v-model="searchValue.status"
            placeholder="请选择退款审核状态"
            style="width: 50%"
            clearable
          >
            <el-option label="待审核" :value="0" />
            <el-option label="已通过" :value="1" />
            <el-option label="未通过" :value="2" />
            <el-option label="审核中" :value="3" />
          </el-select>
          <el-date-picker
            v-model="searchValue.startTime"
            value-format="YYYY-MM-DD"
            type="date"
            placeholder="开始时间"
            :teleported="false"
            style="width: 100%"
          ></el-date-picker>
          <el-date-picker
            v-model="searchValue.endTime"
            value-format="YYYY-MM-DD"
            type="date"
            placeholder="结束时间"
            :teleported="false"
            style="width: 100%"
          ></el-date-picker>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upsearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable
        ref="table"
        :apiObj="apiObj"
        row-key="id"
        stripe
        @row-dblclick="handleRowDblclick"
      >
        <!-- <el-table-column label="ID" prop="id" width="50"></el-table-column> -->
        <el-table-column
          label="客户名称"
          prop="customerName"
          min-width="200"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="合同编码"
          prop="contractCode"
          min-width="200"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="退款金额"
          prop="refundMoney"
          width="100"
        ></el-table-column>
        <el-table-column
          label="退款原由"
          prop="reason"
          width="150"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="退款人"
          prop="refundAdminName"
          width="100"
        ></el-table-column>
        <el-table-column
          label="退款时间"
          prop="createTime"
          width="150"
        ></el-table-column>
        <el-table-column
          label="审核状态"
          prop="status"
          width="100"
          fixed="right"
          sortable
        >
          <template #default="scope">
            <!--0，未审核，1,审核通过，2审核未通过-->
            <p v-if="scope.row.status == 0">待审核</p>
            <p v-if="scope.row.status == 1" style="color: #67c23a">通过</p>
            <p v-if="scope.row.status == 2" style="color: #f56c6c">未通过</p>
            <p v-if="scope.row.status == 3" style="color: #ff9b31">审核中</p>
            <p v-if="scope.row.status == 4" style="color: #f56c6c">作废</p>
            <p v-if="scope.row.status == 5" style="color: #f56c6c">删除</p>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="250">
          <template #default="scope">
            <el-button-group>
              <el-button
                text
                type="primary"
                size="small"
                @click="table_show(scope.row, scope.$index)"
                v-auth-button="['show/returnProduct']"
                >查看</el-button
              >
              <!-- <el-button
                text
                type="primary"
                size="small"
                @click="table_edit(scope.row, scope.$index)"
                v-if="scope.row.status == 0"
                v-auth-button="['edit/refund']"
                >编辑</el-button
              > -->
              <el-popconfirm
                title="确定删除吗？"
                @confirm="table_delete(scope.row, scope.$index)"
                v-if="scope.row.status == 0"
              >
                <template #reference>
                  <el-button
                    text
                    type="primary"
                    size="small"
                    v-auth-button="['delete/refund']"
                    >删除</el-button
                  >
                </template>
              </el-popconfirm>
              <el-popconfirm
                title="确定作废吗？"
                @confirm="table_cancel(scope.row, scope.$index)"
                v-if="scope.row.status == 1"
              >
                <template #reference>
                  <el-button
                    text
                    type="primary"
                    size="small"
                    v-auth-button="['delete/refund']"
                    >作废</el-button
                  >
                </template>
              </el-popconfirm>
            </el-button-group>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
</template>
<script>

export default {
  name: 'returnGoods',
  data () {
    return {
      apiObj: this.$API.produce.refund.getRefundPageList,
      searchValue: {
        contractCode: null,
        customerName: null,
        status: null,
        startTime: null,
        endTime: null
      },
      selection: []

    }
  },

  methods: {
    //添加
    add () {
      this.$router.push({
        path: '/produce/refund/addRefund',
        query: {
          mode: 'add'
        }
      })
    },
    //编辑
    table_edit (row) {
      this.$router.push({
        path: '/produce/refund/addRefund',
        query: {
          mode: 'edit',
          id: row.id
        }
      })
    },
    async table_delete (row) {
      let data = {
        id: row.id,
        status: 4,
      }
      var res = await this.$API.produce.refund.updateStatus.post(data)
      if (res.code == 200) {
        this.$refs.table.refresh()
        this.$message.success("删除成功")
      }
    },
    async table_cancel (row) {
      let data = {
        id: row.id,
        status: 3,
      }
      var res = await this.$API.produce.refund.updateStatus.post(data)
      if (res.code == 200) {
        this.$refs.table.refresh()
        this.$message.success("作废成功")
      }
    },
    //查看
    table_show (row) {
      this.$router.push({
        path: '/produce/refund/refundDetail',
        query: {
          id: row.id
        }
      })
    },


    //搜索
    upsearch () {
      this.$refs.table.upData(this.searchValue)
    },

    // 双击表格
    handleRowDblclick (row) {
      this.table_show(row)
    }

  }
}
</script>

<style>
</style>